package com.good.cm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.good.cm.model.LayUITable;
import com.good.cm.model.ResultInfo;
import com.good.cm.model.TriageListQuery;
import com.good.cm.model.TriagePatientVisitModel;
import com.good.cm.service.PatientVisitService;
import com.good.cm.vo.TriagePatient;
import com.good.cm.vo.TriagePatientVisitInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PatientVisitController {
    @Resource
    private PatientVisitService patientVisitService;

    /**
     * 患者列表分页查询接口
     * @return
     */
    @GetMapping("patient/getPatientListByParm")
    @ResponseBody
    public LayUITable getPatientListByParm(TriageListQuery query){
        Map<String,Object> map=new HashMap<String, Object>();
        System.out.println("传入参数："+query.toString());
        PageHelper.startPage(query.getPage(),query.getLimit());
        List<TriagePatientVisitInfo> data= patientVisitService.getPatientList(query);
        //分页
        PageInfo<TriagePatientVisitInfo> pageInfo=new PageInfo<TriagePatientVisitInfo>(data);
        LayUITable tableObj=new LayUITable();
        tableObj.setCode(0);
        tableObj.setMsg("");
        tableObj.setCount(pageInfo.getTotal());
        tableObj.setData(pageInfo.getList());
        //String jsondata= JSON.toJSONString(tableObj);//实体转json串
        return  tableObj;
    }

    /**
     * 保存分诊全部信息
     * @param triagePatient
     * @return
     */
    @ResponseBody
    @PostMapping("patient/savePatient")
    public ResultInfo savePatient(@RequestBody TriagePatientVisitModel triagePatient){
        //添加失败原因，日期传入格式不对，导致反序列化失败
        return patientVisitService.SaveTriagePatientVisitModel(triagePatient);
    }
    /**
     * 通过pvid获取患者信息系
     * @param pvid
     * @return
     */
    @ResponseBody
    @GetMapping("patient/getPatientInfoByPvid")
    public  ResultInfo getPatientInfoByPvid(String pvid){
        return patientVisitService.getPatientInfoByPvid(pvid);
    }

}
